package org.cuasloi.rabbitmq.work;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WorkProduceController {

    // 注入SpringAMQP提供的模板
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("workQueue/{msg}")
    public void sendMsgToWorkQueue(@PathVariable("msg") String msg) throws InterruptedException {
        // 发送50条消息
        for(int i = 1; i <= 50; i++) {
            // 发送消息到队列
            rabbitTemplate.convertAndSend("work.queue", msg);
            Thread.sleep(20);
        }
    }
}
